import cn.edu.hbsi.dao.WorkerDao;
import cn.edu.hbsi.domain.Worker;
import cn.edu.hbsi.utils.GetSqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Test;

import java.util.Iterator;
import java.util.List;

public class testWorker
{
    private SqlSession sqlSession = GetSqlSessionUtil.getSqlSession();
    private WorkerDao workerDao = sqlSession.getMapper(WorkerDao.class);

    @Test
    public void testSelectAllWorkers(){
        List<Worker> list = workerDao.selectAllWorkers();

        Iterator var = list.iterator();
        while(var.hasNext()){
            System.out.println((Worker)var.next());
        }
    }

    @Test
    public void testSelectWorkerByIdAndName(){
        System.out.println(workerDao.selectWorkerByIdAndName(3,"王五"));
    }

    @Test
    public void testSelectWorkerByWorkerId(){
        System.out.println(workerDao.selectWorkerByWorkerId(1002));
    }

    @Test
    public void testSelectWorkerById(){
        System.out.println(workerDao.selectWorkerById(1));
    }

    @Test
    public void testInsertWorker(){
        Worker worker = new Worker("赵六",18,"女",1004);
        Integer i = workerDao.insertWorker(worker);
        System.out.println(i);
    }

    @Test
    public void testUpdateWorker(){
        Worker worker = new Worker(4,"赵六",18,"女",null);
        Integer i = workerDao.updateWorker(worker);
        System.out.println(i);
    }

    @Test
    public void testDeleteWorker(){
        System.out.println(workerDao.deleteWorker(4));
    }

    @After
    public void destory(){
        sqlSession.commit();
        sqlSession.close();
    }
}
